package analyse;

import java.math.BigDecimal;

import spring.SpringApplicationCtx;

import com.stock.dao.Buysave;
import com.stock.dao.BuysaveDAO;

import data.Constant;
import data.DataBuffer;
import data.LoadData;
import data.TimeStock;

public class PerStock {
	
	public static boolean canBuy(String code) {
		TimeStock ts = LoadData.getTimeStock(code);
		if(ts.getSelectTime()!=null){
			return true;
		}
		if(ts.getRatePercent().compareTo(new BigDecimal(9.9))>0){
			return false;
		}
		boolean a1 = ts.getLastStock().getRatePercent().compareTo(Constant.EIGHT)<0;
		boolean a2 = ts.getInfo()>=0;
		if(a1&&a2){
			if(DataBuffer.getBigdeal().contains(code)&&ts.isHead()){
				ts.setSelectTime(ts.getTime());
				ts.setSelectPrice(ts.getCurPrice());
				
				BuysaveDAO buysaveDAO = (BuysaveDAO)SpringApplicationCtx.getCtx().getBean("BuysaveDAO");
				Buysave bs = new Buysave();
				bs.setUserName("headrun");
				bs.setBuyAmount(ts.getCurPrice());
				bs.setBuyDate(ts.getDate());
				bs.setBuyTime(ts.getTime());
				bs.setNumber(code);
				bs.setBuyPrice(ts.getCurPrice());
				bs.setBuyQty(1);
				bs.setOwnAmount(ts.getCurPrice());
				bs.setOwnQty(1);
				buysaveDAO.save(bs);
				
				return true;
			}
		}
		return false;
	}
	
	public static boolean canBuy2(String code) {
		TimeStock ts = LoadData.getTimeStock(code);
		if(ts.getDayHealth().compareTo(Constant.THREE)>0){
			return true;
		}
		return false;
	}
	
	public boolean saleSign(String code){
		
		return true;
	}
}
